/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.shiep.aurora.calendar;

import work02.w5.model.ScheduleFrequence;

/**
 * 用于界面和控制层转换的适配器
 *
 * @author Eric
 */
public class SchedulePanelAdapter {

    String[] type = {"10分钟", "15分钟", "30分钟", "45分钟", "1小时", "2小时", "3小时", "5小时", "6小时", "12小时", "1天", "2天", "一周"};

    public void IOC(){
        
    }
    
    public long conventModelIndexToAdvancedNoticeMilisecond(int index, Object[] model) {
        /*
         *异常判断 
         */
        if (index > model.length - 1) {
            return 0;
        }
        String s = model[index].toString();
        return conventStringtoDate(s);
    }

    public int conventAdvancedNoticeMilisecondToModelIndex(long advancedNoticeMilisecond, Object[] model) {
        String da = conventDateToString(((int) advancedNoticeMilisecond));
        for (int i = 0; i < model.length; i++) {
            if (da.equals(model[i].toString())) {
                return i;
            }
        }
        return 0;
    }

    public int conventScheduleFrequenceToModelIndex(ScheduleFrequence frequence, Object[] model) {
        for(int i=0;i<model.length;i++) {
            if(conventStringtoScheduleFrequence(frequence).equals(model.toString())) {
                return i;
            }
        }
        return 0;
    }

    public ScheduleFrequence conventModelIndexToScheduleFrequence(int index, Object[] model) {
        if(index>model.length-1) {
            conventStringtoScheduleFrequence("一次性活动");
        } 
       return  conventStringtoScheduleFrequence(model[index].toString());
    }

    private ScheduleFrequence conventStringtoScheduleFrequence(String s) {
        //"一次性活动", "每天", "每周", "每月", "每年"
        switch (s) {
            case "一次性活动":
                return ScheduleFrequence.OnlyOnce;
            case "每天":
                return ScheduleFrequence.EveryDay;
            case "每周":
                return ScheduleFrequence.EveryWeek;
            case "每月":
                return ScheduleFrequence.EveryMonth;
            case "每年":
                return ScheduleFrequence.EveryYear;
            default:
                return ScheduleFrequence.OnlyOnce;
        }
    }
    
      private String conventStringtoScheduleFrequence( ScheduleFrequence f) {
        //"一次性活动", "每天", "每周", "每月", "每年"
        switch (f) {
            case OnlyOnce:
                return "一次性活动";
            case EveryDay:
                return "每天";
            case EveryWeek :
                return "每周";
            case  EveryMonth:
                return "每月";
            case EveryYear:
                return  "每年";
            default:
                return "一次性活动";
        }
    }
    

    private long conventStringtoDate(String time) {
        switch (time) {
            case "10分钟":
                return 10 * 60 * 1000;
            case "15分钟":
                return 15 * 60 * 1000;
            case "30分钟":
                return 30 * 60 * 1000;
            case "45分钟":
                return 45 * 60 * 1000;
            case "1小时":
                return 1 * 60 * 60 * 1000;
            case "2小时":
                return 2 * 60 * 60 * 1000;
            case "3小时":
                return 3 * 60 * 60 * 1000;
            case "5小时":
                return 5 * 60 * 60 * 1000;
            case "6小时":
                return 6 * 60 * 60 * 1000;
            case "12小时":
                return 12 * 60 * 60 * 1000;
            case "1天":
                return 1 * 24 * 60 * 60 * 1000;
            case "2天":
                return 2 * 24 * 60 * 60 * 1000;
            case "一周":
                return 7 * 24 * 60 * 60 * 1000;
            default:
                return 0;
        }
    }

    private String conventDateToString(int date) {
        switch (date) {
            case 10 * 60 * 1000:
                return "10分钟";
            case 15 * 60 * 1000:
                return "15分钟";
            case 30 * 60 * 1000:
                return "30分钟";
            case 45 * 60 * 1000:
                return "45分钟";
            case 1 * 60 * 60 * 1000:
                return "1小时";
            case 2 * 60 * 60 * 1000:
                return "2小时";
            case 3 * 60 * 60 * 1000:
                return "3小时";
            case 5 * 60 * 60 * 1000:
                return "5小时";
            case 6 * 60 * 60 * 1000:
                return "6小时";
            case 12 * 60 * 60 * 1000:
                return "12小时";
            case 1 * 24 * 60 * 60 * 1000:
                return "1天";
            case 2 * 24 * 60 * 60 * 1000:
                return "2天";
            case 7 * 24 * 60 * 60 * 1000:
                return "一周";
            default:
                return "10分钟";
        }
    }
}
